#ifndef BDTHREAD_H
#define BDTHREAD_H

#include <thread>
#include <functional>

static unsigned int __stdcall threadFunction(void* pThread, void* data);

class BDThread
{
	friend unsigned int __stdcall threadFunction(void* pThread, void* data);

public:
	BDThread();
	BDThread(std::function<void*(void*)> function);
	virtual ~BDThread();

	virtual void* Run(void* data);

	int Start(void* data = NULL);

	void Detach();

	void Wait();
	
	void Stop();

	static void Sleep(int ms);

private:

	std::thread m_Thread;
	std::function<void*(void*)> m_Function;
	bool m_bStarted;
	bool m_bDetached;
	unsigned int m_hTheadID;
};

#endif